package com.kye.api_gateway.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;


@Component
public class GlobalRouteFilter implements GlobalFilter, Ordered {

	private Logger logger = LoggerFactory.getLogger(GlobalRouteFilter.class);

	public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
		Long start = System.currentTimeMillis();
		Long end = System.currentTimeMillis();
		logger.info("请求路径：{}，耗时：{}毫秒",exchange.getRequest().getURI(),end-start);
		System.out.println("请求路径："+exchange.getRequest().getURI()+"，耗时,毫秒"+(end-start));
		return chain.filter(exchange);
	}

	public int getOrder() {
		// TODO Auto-generated method stub
		return -100;
	}

}
